package com.abcdefg.orderservice.controller;


import com.abcdefg.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/createOrder1")
    public String createOrder1() {
        //下单相关操作, ⽐如参数校验, 操作数据库等, 代码省略
        //发送消息通知
        String orderId = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("", "order.create", "下单成功, 订单ID:" + orderId);
        return "下单成功";
    }

    @RequestMapping("/createOrder2")
    public String createOrder2() {
        //下单相关操作, ⽐如参数校验, 操作数据库等, 代码省略
        //发送消息通知
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId("订单号："+UUID.randomUUID().toString());
        orderInfo.setCustomerId("商品号："+Math.random());
        rabbitTemplate.convertAndSend("", "order.create", orderInfo);
        return "下单成功";
    }
}
